package com.yuan.leetcode;

public class LeetCode {

    public static void main(String[] args) {

    }

    public int diffNumber(int[] nums) {
        long number = 0L;
        for (int nu : nums) {
            number += nu;
        }
        return (int) ((nums.length + 1) * (nums.length) / 2 - number);
    }

    public int diffNumber2(int[] nums) {
        int i = 0;
        int j = nums.length - 1;
        int m = 0;
        while (i <= j) {
            m = (i + j) / 2;
            if (m == nums[m]) {
                i = m + 1;
            } else {
                j = m - 1;
            }
        }
        return i;
    }

}
